"""
@name : 错误与异常
@author : wenyao
@projectname: xsfh
"""
#常见的异常类
#NameError
#变量没有被定义，找不到
# print(b)

#ZeroDivisionError  除数为0
#a = 1/0

#IndentationError: unexpected indent  缩进错误
# print("ok")

#SyntaxError: invalid syntax  语法错误
# if 1>0::
#     print("ok")

#IndexError: list index out of range
# a = [1,2,3]
# print(a[4])

#KeyError: 'c'
# dict1 = {"a":1,"b":2}
# dict1["c"]

#AttributeError: module 'math' has no attribute 'xxx'
# import math
# math.xxx()

#ValueError: invalid literal for int() with base 10: 'abc'
#参数传递类型不正确
# int("abc")

#FileNotFoundError: [Errno 2] No such file or directory: 'test.txt'
# fp = open("test.txt")

#AssertionError
# assert 0>1

# print("abc.......")
# 1/0
# print("end.......")

#一旦发生异常 程序就结束了
# try:
#     #执行的代码
#     pass
# except:
#     #发生异常时，应该处理的流程
#     pass
#
# try:
#     pass
# except IndexError as ie:
#     pass

# try ...except 异常捕获
#except捕获的错误与程序触发的错误不一致，程序就会捕获不到
#except 可以有多个，匹配到第一个就退出
#如果父类异常在最前面，会吞噬掉所有的子类异常

#Exception
# try:
#     print("start try......")
#     a = 1/0
#     print("end try.....")
# except IndexError as ie:
#     print("index error:",ie)
# except ZeroDivisionError as ze:
#     #发生除数为0 异常时，要做的事情
#     print("zero error:",ze)
# except Exception as e:
#     print("exception error:",e)
# print("ending.....")

#else结构
#没有发生任何异常时处理else语句块
# try:
#     print("else....")
#     a = 1/0
# except Exception:
#     print("exception...")
# else:
#     print("this is else test")

#finally结构
#不管有没有异常， 不管异常有没有被捕获 它都执行
# try:
#     print("start.....")
#     a = 1/0
# except IndexError:
#     print("this is index error")
# finally:
#     print("this is finally")

#异常嵌套
# def aa():
#     try:
#         a = "hello world"
#         try:
#             int(a)
#         except:
#             print("value error")
#             return "i am value error"
#         finally:
#             print("i am finally 1....")
#         print(name)
#     except:
#         print("name error")
#     finally:
#         print("i am finally 2....")
#
# b = aa()

#手动触发异常
#raise 异常类("说明信息")
# raise IndexError
# raise IndexError("THIS IS INDEX ERROR")
# raise RuntimeError


# try:
#     a = 1/0
#     lst = [1,2,3]
#     print(lst[4])
# except IndexError as ie :
#     print("index error")
# except ZeroDivisionError as ze:
#     print("zero error")

# try:
#     pass
# finally:
#     pass

#python3
# except IndexError as ie :
#python2
# except IndexError , ie :

# python2编码： ascii码
# python3编码： utf-8

#192.168.0.0/24网段  -- 192.168.0.1 ~ 192.168.0.255
#这个段的ip地址哪些是被使用